
	use "$root/output/analysis_finaldataset.dta", clear
		
	lab var male			 "Male"
	lab var learning 		 "Foundational Learning (z-score)"
	lab var kn_eyos  		 "Average schooling (years)"
	lab var returns_std 	 "LM Returns (z-score)"
	lab var script_posterior "Scripted lessons (0-4 scale)"
	lab var loggdp 			 "(Log) GDP per Capita"

	global beliefs 	  learning kn_eyos returns_std growth script_posterior
	global ind 		  male agency2
	global country    tvetshare unemp

*-----------------------------
//	 Table 6: Explaining Spending Preferences
*-----------------------------

	est clear
	eststo m1 : qui reg found_index2 $beliefs 			    ib4.regioncode ,  cl(country_id)
	eststo m2 : qui reg found_index2 $beliefs $ind $country ib4.regioncode ,  cl(country_id)
	eststo m3 : qui reg tvet_index2  $beliefs 			    ib4.regioncode ,  cl(country_id)
	eststo m4 : qui reg tvet_index2  $beliefs $ind $country ib4.regioncode ,  cl(country_id)
	estadd ysumm : m1 m2 m3 m4

	//Stata output
	estout, replace type style(smcl) ///
				label stats(ymean N r2,fmt(1 %9.0gc 3)labels("Outcome Mean" "N" "R2")) cells(b(star fmt(3)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) noomitted ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
				mlabels("" "" "" "",numbers)mgroups("FLN" "TVET",pattern(1 0 1 0)) collabels(none) nobaselevels ///
				refcat(learning "\hline \textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" male "\hline \textit{Respondent Characteristics:}", nolabel)

	//Latex Table			
	esttab using tables/explainingprefs.tex, replace nonumbers se label booktabs ///
				stats(N r2,fmt(%9.0gc 2)labels("\hline Obs." "\hline R\sym{2}")) noomitted starlevels(* 0.1 ** 0.05 *** 0.01)  ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
				mlabels("" "" "" "",numbers)mgroups("FLN" "TVET",pattern(1 0 1 0)span prefix(\multicolumn{@span}{c}{) suffix(})) collabels(none) nobaselevels ///
				refcat(learning "\textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" ///
					   male "\hline \textit{Respondent Characteristics:}" tvetshare "\hline \textit{Country Characteristics:}", nolabel) ///
				nonotes compress nogaps

// Appendix				
				
*-----------------------------			
// 	Different FL/TVET Measures
*-----------------------------

	foreach var of varlist *_top3 priority*_top *_binary{
	replace `var'=`var'/100		
	}			

	lab var learning 	"Foundational Learning"
	lab var kn_eyos  	"Average schooling (years)"
	lab var returns_std "LM Returns (z-score)"
	lab var script_posterior "Scripted lessons (0-4 scale)"
	lab var loggdp "(Log) GDP per Capita"
	lab var agency2		"TVET Agency"
	lab var unemp 		"Grad unemployment"

				
	est clear			
	eststo m1 : qui reg sdg_found_top 	 			  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m2 : qui reg sdg_found_top3 	 			  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m3 : qui reg priority_foundational_top	  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m4 : qui reg priority_foundational_binary  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m5 : qui reg sdg_tvet_top 	 			  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m6 : qui reg sdg_tvet_top3 	 			  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m7 : qui reg priority_tvet_top	  		  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m8 : qui reg priority_tvet_binary  		  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	estadd ysumm : m1 m2 m3 m4 m5 m6 m7 m8
	
	//Stata output
	estout, replace type style(smcl) ///
				label stats(ymean N r2,fmt(2 %9.0gc 3)labels("Outcome Mean" "N" "R2")) cells(b(star fmt(3)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) noomitted ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
				mlabels("Top" "Top 3" "Top" "Top 3" "Top" "Top 3" "Top" "Top 3")mgroups("FL - SDG" "FL - Aid" "TVET - SDG" "TVET - Aid",pattern(1 0 1 0 1 0 1)span) collabels(none) nobaselevels ///
				refcat(learning "\hline \textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" male "\hline \textit{Respondent Characteristics:}", nolabel)

	//Latex Table			
	esttab using tables/explainingprefs2.tex, replace nonumbers se label booktabs ///
				stats(ymean N r2,fmt(2 %9.0gc 2)labels("\hline Outcome Mean" "Obs." "R\sym{2}")) noomitted starlevels(* 0.1 ** 0.05 *** 0.01)  ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///`'
				mlabels("Top" "Top 3" "Top" "Top 3" "Top" "Top 3" "Top" "Top 3")mgroups("FL - SDG" "FL - Aid" "TVET - SDG" "TVET - Aid",pattern(1 0 1 0 1 0 1)span prefix(\multicolumn{@span}{c}{) suffix(})) collabels(none) nobaselevels ///
				refcat(learning "\textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" ///
					   male "\hline \textit{Respondent Characteristics:}" tvetshare "\hline \textit{Country Characteristics:}", nolabel) ///
				nonotes compress nogaps


*-----------------------------
// All preference outcomes
*-----------------------------			
	est clear
	eststo m1 : qui reg sdg_found_top3 	 	$beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m2 : qui reg sdg_tvet_top3 	 	$beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m3 : qui reg sdg_empl_top3  		$beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m4 : qui reg sdg_sust_top3	    $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m5 : qui reg sdg_adult_top3 	 	$beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m6 : qui reg sdg_gender_top3		$beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m7 : qui reg sdg_ecd_top3  		$beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m8 : qui reg sdg_secondary_top3  $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	estadd ysumm : m1 m2 m3 m4 m5 m6 m7 m8
	
	//Stata output
	estout, replace type style(smcl) ///
				label stats(ymean N r2,fmt(1 %9.0gc 3)labels("Outcome Mean" "N" "R2")) cells(b(star fmt(3)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) noomitted ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
				mlabel(,depvars) nobaselevels ///
				refcat(learning "\hline \textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" male "\hline \textit{Respondent Characteristics:}", nolabel)
	
	//Latex Table
	esttab using tables/explainingprefs3.tex, replace nonumbers se label booktabs ///
					stats(ymean N r2,fmt(2 %9.0gc 2)labels("\hline Outcome Mean" "Obs." "R\sym{2}")) noomitted starlevels(* 0.1 ** 0.05 *** 0.01)  ///
					drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
					mlabels("Foundational" "TVET" "Empl" "Skills" "Adult" "Gender" "ECD" "USE") collabels(none) nobaselevels ///
					refcat(learning "\textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" ///
						   male "\hline \textit{Respondent Characteristics:}" tvetshare "\hline \textit{Country Characteristics:}", nolabel) ///
					nonotes compress nogaps

	est clear
	eststo m1 : qui reg priority_foundational_binary $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m2 : qui reg priority_tvet_binary 	 	 $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m3 : qui reg priority_construction_binary $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m4 : qui reg priority_ppp_binary  		 $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	eststo m5 : qui reg priority_computers_binary  	 $beliefs $ind $country			    ib4.regioncode ,  cl(country_id)
	estadd ysumm : m1 m2 m3 m4 m5
	
	//Stata output
	estout, replace type style(smcl) ///
				label stats(ymean N r2,fmt(1 %9.0gc 3)labels("Outcome Mean" "N" "R2")) cells(b(star fmt(3)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) noomitted ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
				mlabel(,depvars) nobaselevels ///
				refcat(learning "\hline \textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" male "\hline \textit{Respondent Characteristics:}", nolabel)
		
	//Latex Table	
	esttab using tables/explainingprefs4.tex, replace nonumbers se label booktabs ///
					stats(ymean N r2,fmt(2 %9.0gc 2)labels("\hline Outcome Mean" "Obs." "R\sym{2}")) noomitted starlevels(* 0.1 ** 0.05 *** 0.01)  ///
					drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
					mlabels("Foundational" "TVET" "Construction" "PPP" "Computers") collabels(none) nobaselevels ///
					refcat(learning "\textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" ///
						   male "\hline \textit{Respondent Characteristics:}" tvetshare "\hline \textit{Country Characteristics:}", nolabel) ///
					nonotes compress nogaps

*-----------------------------					
// Main Table (Original sample list)
*-----------------------------

	keep if googlelist==1
	est clear
	eststo m1 : qui reg found_index2 $beliefs 			    ib4.regioncode ,  cl(country_id)
	eststo m2 : qui reg found_index2 $beliefs $ind $country ib4.regioncode ,  cl(country_id)
	eststo m3 : qui reg tvet_index2  $beliefs 			    ib4.regioncode ,  cl(country_id)
	eststo m4 : qui reg tvet_index2  $beliefs $ind $country ib4.regioncode ,  cl(country_id)
	estadd ysumm : m1 m2 m3 m4
	
	//Stata output
	estout, replace type style(smcl) ///
				label stats(ymean N r2,fmt(1 %9.0gc 3)labels("Outcome Mean" "N" "R2")) cells(b(star fmt(3)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) noomitted ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
				mlabels("" "" "" "",numbers)mgroups("FLN" "TVET",pattern(1 0 1 0)) collabels(none) nobaselevels ///
				refcat(learning "\hline \textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" male "\hline \textit{Respondent Characteristics:}", nolabel)

	//Latex Table
	esttab using tables/explainingprefs_robustness.tex, replace nonumbers se label booktabs ///
				stats(N r2,fmt(%9.0gc 2)labels("\hline Obs." "\hline R\sym{2}")) noomitted starlevels(* 0.1 ** 0.05 *** 0.01)  ///
				drop (_cons) indicate("Region FE = *regioncode", label("Yes" "")) ///
				mlabels("" "" "" "",numbers)mgroups("FLN" "TVET",pattern(1 0 1 0)span prefix(\multicolumn{@span}{c}{) suffix(})) collabels(none) nobaselevels ///
				refcat(learning "\textit{Beliefs about reality:}" script_posterior "\hline \textit{Beliefs about interventions:}" ///
					   male "\hline \textit{Respondent Characteristics:}" tvetshare "\hline \textit{Country Characteristics:}", nolabel) ///
				nonotes compress nogaps
